<%@page import="javax.xml.ws.Response"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ page import="org.hibernate.SessionFactory"%>
<%@ page import="org.hibernate.Session"%>
<%@ page import="java.util.List"%>
<%@ page import="hibernate.model.*"%>
<%@ page import="hibernate.util.HibernateUtil"%>
<%@ page import="hibernate.method.*"%>
<script src="js/edit_profile.js"></script>
<script src="js/jquery-1.11.0.js"></script>


<div class="page-header">
	<h2 class="page-title">Edycja danych</h2>
</div>

<br />

<div id="content">
	<%
		SessionFactory sessionFactory = HibernateUtil
			.getSessionAnnotationFactory();
			Session s = sessionFactory.openSession();
			s.beginTransaction();
			UserMethods user_m = new UserMethods();

			Integer user_id = (Integer) session.getAttribute("user_id");
			response.setContentType("text/html");
			if (user_id != null) {
		User u = user_m.id_to_user(sessionFactory, s, user_id);
	%>

	

	<form action="../EditUser" method="POST" name='formularz' enctype="multipart/form-data">

		<table>
			<tr>
				<td>Nick:</td>
				<td>
				<input type="hidden" name="user_id" id="user_id" value="<%=u.getUser_id()%>">
					<%
						out.println(u.getUsername());
					%>
				</td>

			</tr>
			<tr>

				<td>Data urodzenia:</td>
				<td><input type="date" id="birth_date" name="birth_date"
					placeholder="<%=u.getBirthdate()%>" value="<%=u.getBirthdate()%>"
					pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))">
				</td>

			</tr>

			<tr>

				<td>Podaj email:</td>
				<td><input type="email" name="email"
					placeholder="<%out.println(u.getEmail());%>" maxlength="255"
					pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"></td>

			</tr>

			<tr>
				<td>Hasło:</td>
				<td><input type="password" id="password" name="password"
					 maxlength="80"></td>

			</tr>
			<tr>
				<td>Powtórz haslo:</td>
				<td><input type="password" id="confirm_password" 
					name="confirm_password" maxlength="80"></td>

			</tr>
			<tr>
				<td>Avatar:</td>
				<td><input type="file" name="avatar" id="avatar"></td>
				<td> <img src="main/userAvatar.jsp?user_id=<%=(Integer) session.getAttribute("user_id") %>" alt="UserAvatar" class="img-circle" style="height: 115px">
				<br>
				Aktualny avatar
				</td>
				
			</tr>
			<tr>
				<td><input type="hidden" id="type" name="type" value="client" />
				</td>
			</tr>
			<tr>
				<td>Płec:</td>
				<td><select id="gender" name="gender">
						<%
							if (u.getGender() == "male") {
						%>
						<option value="male" selected>męzczyzna</option>
						<option value="female">kobieta</option>

						<%
							} else {
						%>
						<option value="male">męzczyzna</option>
						<option value="female" selected>kobieta</option>
						<%
							}
						%>
				</select></td>

			</tr>
			<tr>
				<td>Imię: *</td>
				<td><input type="text" name="name" id="name"
					placeholder="<%out.println(u.getName());%>" maxlength="255"></td>

			</tr>
			<tr>
				<td>Nazwisko: *</td>
				<td><input type="text" name="surname" id="surname"
					placeholder="<%String surname = u.getSurname();
				if (surname != null)
					out.println(surname);%>"
					maxlength="255"></td>

			</tr>
			<tr>
				<td>Numer telefonu: *</td>
				<td><input type="tel" name="phone" id="phone"
					placeholder="<%String phone = u.getPhone();
				if (phone != null)
					out.println(phone);%>"
					maxlength="80" pattern="\d{3}[\-]\d{3}[\-]\d{3}"></td>

			</tr>

		</table>
		<input type="submit" class="mainBtn" value="Zmień dane"> <br />
		* - Pomocne w przypadku rezerwacji stolika za posrednictwem
		HexGamesSocial
	</form>
	<%
		} 
		s.getTransaction().commit();
	%>
</div>
